package com.cdut.self.controller;

import com.cdut.self.pojo.dto.UserDTO;
import com.cdut.self.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/********************
 *
 * @author chentao
 * @date 2020/7/23 9:50 上午
 ********************/
@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/list")
    public List<UserDTO> list(){
        return userService.findAll();
    }

    @GetMapping("/id")
    public UserDTO getUser(@PathVariable("id") Integer id) {
        return userService.findById(id);
    }

    @PostMapping()
    public Integer add(@RequestBody UserDTO userDTO) {
        return userService.addUser(userDTO);
    }
}
